﻿using System.Reflection;
using System.Deployment.Application;

namespace Red.Core
{
    /// <summary>
    /// Utility class to obtain version of application.
    /// Application's deployed via click-once publishing keep this information in ApplicationDeployment.CurrentDeployment.
    /// Normal application (standalone mode) keeps this information directly in Assembly.
    /// </summary>
    public class AppVersion
    {
        public static string ApplicationVersion
        {
            get
            {
                try
                {
                    return ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString();
                }
                catch
                {
                    return Assembly.GetExecutingAssembly().GetName().Version.ToString();
                }
            }
        }

        public static string TitleWithVersion( string titleFormat )
        {
            return string.Format( titleFormat, ApplicationVersion );
        }
    }
}
